<template>
  <div>
    <!-- Vue中 id 换ref -->
    <div
      ref="main"
      style="width: 600px; height: 300px; background-color: bisque"
    ></div>
    <button @click="firstEchart">AboutView</button>
    <div ref="second" style="width: 600px; height: 300px; background-color: bisque" ></div>
    <button @click="secondChart">secondChart</button>
  </div>
</template>
<script lang="ts">
/**
 * 页面核心数据结构体说明文档
 *
 *
 */
// import from
import { defineComponent } from "vue";
import * as echarts from "echarts";
export default defineComponent({
  name: "AboutView",
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
    };
  },
  computed: {
    /* sampleC() {
      return this.sampleD + "--";
    }, */
  },
  created() {},
  mounted() {
    // console.log(echarts)
  },
  methods: {
    // sampleM() {},
    secondChart(){
      // const xData= [1,2,3,4,5,6,7,8]
      //  [-100 ,100 ] 2 
      const xData = [];
      for (let i = -100; i <=100 ;) {
        xData.push(i)
          // i++;
          i=i+2;
          
      }
      // y = x2 +2x+1
      const yData= []
      for (let i = 0; i < xData.length; i++) {
          yData[i]=xData[i]*xData[i] +2* xData[i]+1
      }
      // console.log(yData)
      const second: any = this.$refs["second"];
      const myChart = echarts.init(second);
      myChart.setOption({
        title: {
          text: "y=x2+2x+1",
        },
        tooltip: {},
        xAxis: {
          data: xData,
        },
        yAxis: {},
        // content  dimension serie
        series: [
          {
            name: "a",
            type: "bar",
            data: yData,
          },
          
        ],
      });
    },

    firstEchart() {
      // 初始化一块画布
      // 画布就是一个有宽高的div标签
      //  const main =  document.getElementById("main")
      const main: any = this.$refs["main"];
      const myChart = echarts.init(main);
      // 绘制图表
      myChart.setOption({
        title: {
          text: "ECharts 入门示例",
        },
        tooltip: {},
        xAxis: {
          data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子","ssss"],
        },
        yAxis: {},
        // content  dimension serie
        series: [
          {
            name: "销量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20,31],
          },
          {
            name: "存量",
            type: "line",
            data: [2, 3, 4, 5, 6, 7,8],
          },
          {
            name: "总量",
            type: "scatter",
            data: [7, 23, 40, 55, 55, 66,77],
          },
        ],
      });
    },
  },
  watch: {
    // sampleP(n, o) {},
  },
});
</script>

<!--<style scoped>-->
<style lang="scss" scoped></style>
